package com.bjpowernode.controller;

import com.bjpowernode.entity.TClue;
import com.bjpowernode.result.Result;
import com.bjpowernode.service.ClueService;
import com.github.pagehelper.PageInfo;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

@RestController
@RequiredArgsConstructor
public class ClueController {

    private final ClueService clueService;

    /**
     * 分页查询线索
     */
    @GetMapping("/api/clues")
    public Result clues(Integer current) {
        PageInfo<TClue> pageInfo = clueService.getClueByPage(current);
        return Result.OK(pageInfo);
    }

    /**
     * excel导入
     * <p>
     * 参数名excelFile要与前端传入的name一致
     */
    @PostMapping("api/importExcel")
    public Result importExcel(MultipartFile excelFile) throws IOException {
        //获取上传excel的文件流数据
        clueService.importExcel(excelFile.getInputStream());
        return Result.OK();
    }


    @GetMapping("/api/clue/{id}")
    public Result getClueById(@PathVariable Integer id) {
        TClue tClue = clueService.getClueById(id);

        return Result.OK(tClue);
    }
}
